
<?php 

class Encryption extends CI_Controller {



    function __construct(){
    parent::__construct();
    
         
       
    }
  /* The default function that gets called when visiting the page */
  public function index() {       
   /*
	$iv = "45287112549354892144548565456541";
	$key = "anjueolkdiwpoida";
	$text = "This is my encrypted message";
	
	// to append string with trailing characters as for PKCS7 padding scheme
	$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_256,MCRYPT_MODE_CBC);
	$padding = $block - (strlen($text)%$block);
	$text .= str_repeat(chr($padding),$padding);
	
	$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key,$text,MCRYPT_MODE_CBC,$iv);
	
	$crypttext64 = base64_encode($crypttext);
	print($crypttext64)."<br/><br/>";*/
	$ky = 'lkirwf897+22#bbtrm8814z5qq=498j5'; // 32 * 8 = 256 bit key
	$iv = '741952hheeyy66#cs!9hjv887mxx7@8y'; // 32 * 8 = 256 bit iv
 
	$text = "Here is my data to encrypt!!!";
 
	$from_vb = "QBlgcQ2+v3wd8RLjhtu07ZBd8aQWjPMfTc/73TPzlyA=";   // enter value from vb.net app here to test
 
	$etext = $this->encryptRJ256($ky, $iv, $text);
	$dtext = $this->decryptRJ256($ky, $iv, $etext);
	$vtext = $this->decryptRJ256($ky, $iv, $from_vb);
 
	echo "<br/>orignal string: ".$text;
	echo "<br/><br/>encrypted in php: ".$etext;
	echo "<br/><br/>decrypted in php: ".$dtext;
	echo "<br/><br/>encrypted in vb: ".$from_vb;
	echo "<br/><br/>from vb decrypted in php: ".$vtext;
	echo "<br/><br/>If you like it say thanks! ";
 
	
  }
  function decryptRJ256($key,$iv,$string_to_decrypt)
	{
 
	$string_to_decrypt = base64_decode($string_to_decrypt);
 
	$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
 
	$rtn = rtrim($rtn, "\4");
 
	return($rtn);
 
	}
 
	function encryptRJ256($key,$iv,$string_to_encrypt)
	{
	 
	$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
	 
	$rtn = base64_encode($rtn);
	 
	return($rtn);
			
	}
  
  
}
?>